package com.larry.mr.partitioner;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @ProjectName hadoop
 * @Author larry
 * @Date 23:33 2021/11/14
 * @Description TODO
 **/
public class WordCountMapper extends Mapper<LongWritable, Text,Text, IntWritable> {

    private Text text = new Text();
    private IntWritable outV = new IntWritable(1);


    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
        System.out.println("setup...................");
    }

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] split = value.toString().split(" ");

        for (String s : split) {
            text.set(s);
            context.write(text,outV);
        }
    }

    @Override
    protected void cleanup(Context context) throws IOException, InterruptedException {
        System.out.println("cleanup........");
    }
}
